package br.ufpe.cin.analysis.plugin.models;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import br.ufpe.cin.analysis.plugin.entities.Process;

public abstract class XMLMannager {


	public static Object load(Class c, File xmlFile ) throws IOException, JAXBException
	{	
		FileInputStream in = new FileInputStream( xmlFile );

		JAXBContext context = JAXBContext.newInstance(c);


		Unmarshaller unmarshaller = context.createUnmarshaller();

		Object r = (Process)unmarshaller.unmarshal(in);

		in.close();

		return r;

	}

	public static void store(Class c, Object ob, File xmlFile) throws JAXBException, IOException
	{
		FileOutputStream out = new FileOutputStream( xmlFile );

		JAXBContext context = JAXBContext.newInstance(c);

		Marshaller marshaller = context.createMarshaller();

		marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

		marshaller.marshal(ob,out);

		out.close();

	}

}
